package com.example.lib.utils.glide;

import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;

import androidx.annotation.NonNull;

import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;

import java.security.MessageDigest;

/**
 * 圆形图片
 */
public class GlideCFitXyTransform extends BitmapTransformation {
    private static final String ID = GlideCFitXyTransform.class.getName();
    private static final byte[] ID_BYTES = ID.getBytes(CHARSET);

    @Override
    protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
        return Bitmap.createScaledBitmap(toTransform, outWidth, outHeight, false);
    }

    @Override
    public int hashCode() {
        return ID.hashCode();
    }

    //可通过内部算法 重写此方法自定义图片缓存key
    @Override
    public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
        messageDigest.update(ID_BYTES);
    }
}
